package com.xx.happychatboot.serve.user.service.impl;

import com.xx.happychatboot.serve.user.domain.entity.UserFriend;
import com.xx.happychatboot.serve.user.domain.vo.response.UserFriendVo;
import com.xx.happychatboot.serve.user.mapper.UserFriendMapper;
import com.xx.happychatboot.serve.user.service.IUserFriendService;
import io.mybatis.service.AbstractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Objects;

@Service
public class UserFriendServiceImpl extends AbstractService<UserFriend, Long, UserFriendMapper> implements IUserFriendService {
    @Autowired
    private UserFriendMapper userFriendMapper;

    @Override
    public List<UserFriendVo> getContactList(Long userId) {
        if (Objects.isNull(userId)) {
            throw new RuntimeException("异常错误，请联系管理员");
        }
        return userFriendMapper.getContactList(userId);
    }

    /**
     * 构建新的好友对象
     * @param uid
     * @param targetId
     * @return
     */
    @Override
    public UserFriend buildNewFriend(Long uid, Long targetId) {
        return UserFriend.builder()
                .uid(uid)
                .friendUid(targetId)
                .deleteStatus(0)
                .createTime(new Date())
                .updateTime(new Date())
                .build();
    }
}
